//Thanh Lam: add keywords to search panel.
	function addKeywords(options){
		//fields
		this.keyword = options.keyword;
		this.research_location_value = options.research_location_value!="" ?  options.research_location_value : "Research location"; 
		this.organisation_involved_value = options.organisation_involved_value!="" ?  options.organisation_involved_value : "Organisation involved";
		this.investigator_value = options.investigator_value!="" ?  options.investigator_value : "Investigators";
		this.type_of_project_default_value = options.type_of_project_value!="" ?  options.type_of_project_value : "Type of project";
		
		var keyword_input = $("keywords");// input keywords control
	
		var research_location = $("research_location");		
		var investigator = $("investigator");		
		var organisation_involved = $("organisation_involved");		
		var type_of_project = $("type_of_project");		
		var layout = "ajax_result";		
		var perpage = $("perpage").getSelected().get("value");
		var sortBy  = $("sortBy");
		
		if(perpage != $("ajax-limit").value){				
			$("ajax-limit").set({value : perpage});				
		}
		if(sortBy.value != $("ajax-filter_order").value){
			$("ajax-filter_order").set({value : sortBy.value});			
		}	
		
		
		/*Keywords*/
		if (keyword_input.value != "" && keyword_input.value != this.keyword) {			
			addRemoveKeywordHeader();
			switch("")
			{
				case $("ajax-keywords0").value:					
					$("ajax-keywords0").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords1").value:
					$("ajax-keywords1").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords2").value:
					$("ajax-keywords2").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords3").value:
					$("ajax-keywords3").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords4").value:
					$("ajax-keywords4").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords5").value:
					$("ajax-keywords5").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords6").value:
					$("ajax-keywords6").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords7").value:
					$("ajax-keywords7").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords8").value:
					$("ajax-keywords8").set({value : keyword_input.value});
				  break;
				case $("ajax-keywords9").value:
					$("ajax-keywords9").set({value : keyword_input.value});
				  break;  
				
				default:
			}	
			keyword_input.set({value : this.keyword});
		}
		if ($("ajax-keywords0").value != "") {			
			addRemoveKeywordHeader();
			$("current-keywords0").removeClass("hidden");
			$("current-keywords0-value").set({text : $("ajax-keywords0").value });			
			$("current-keywords0-dispose").addEvent('click', function() {
				$("current-keywords0-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords0").addClass("hidden");
				$("ajax-keywords0").set({value : ""});				
				ajaxsubmit();
			});		
		}

		
		if ($("ajax-keywords1").value != "") {			
			addRemoveKeywordHeader();
			$("current-keywords1").removeClass("hidden");
			$("current-keywords1-value").set({ text : "AND (" + $("ajax-keywords1").value +")" });			
			$("current-keywords1-dispose").addEvent('click', function() {
				$("current-keywords1-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords1").addClass("hidden");
				$("ajax-keywords1").set({value : ""});				
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords2").value != "") {		
			addRemoveKeywordHeader();
			$("current-keywords2").removeClass("hidden");
			$("current-keywords2-value").set({text : "AND ("+$("ajax-keywords2").value+")" });			
			$("current-keywords2-dispose").addEvent('click', function() {
				$("current-keywords2-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords2").addClass("hidden");
				$("ajax-keywords2").set({value : ""});
				ajaxsubmit();
			});		
		}
	
		if ($("ajax-keywords3").value != "") {	
			addRemoveKeywordHeader();
			$("current-keywords3").removeClass("hidden");
			$("current-keywords3-value").set({text : "AND ("+$("ajax-keywords3").value+")" });		
			$("current-keywords3-dispose").addEvent('click', function() {
				$("current-keywords3-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords3").addClass("hidden");
				$("ajax-keywords3").set({value : ""});
				ajaxsubmit();				
			});		
		}
		
		if ($("ajax-keywords4").value != "") {		
			addRemoveKeywordHeader();
			$("current-keywords4").removeClass("hidden");
			$("current-keywords4-value").set({text : "AND ("+$("ajax-keywords4").value+")" });			
			$("current-keywords4-dispose").addEvent('click', function() {
				$("current-keywords4-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords4").addClass("hidden");
				$("ajax-keywords4").set({value : ""});
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords5").value != "") {			
			addRemoveKeywordHeader();
			$("current-keywords5").removeClass("hidden");
			$("current-keywords5-value").set({text : "AND ("+$("ajax-keywords5").value+")" });		
			$("current-keywords5-dispose").addEvent('click', function() {
				$("current-keywords5-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords5").addClass("hidden");
				$("ajax-keywords5").set({value : ""});
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords6").value != "") {			
			addRemoveKeywordHeader();
			$("current-keywords6").removeClass("hidden");
			$("current-keywords6-value").set({text : "AND ("+$("ajax-keywords6").value+")" });			
			$("current-keywords6-dispose").addEvent('click', function() {
				$("current-keywords6-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords6").addClass("hidden");
				$("ajax-keywords6").set({value : ""});
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords7").value != "") {		
			addRemoveKeywordHeader();
			$("current-keywords7").removeClass("hidden");
			$("current-keywords7-value").set({text : "AND ("+$("ajax-keywords7").value+")" });		
			$("current-keywords7-dispose").addEvent('click', function() {
				$("current-keywords7-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords7").addClass("hidden");
				$("ajax-keywords7").set({value : ""});
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords8").value != "") {	
			addRemoveKeywordHeader();
			$("current-keywords8").removeClass("hidden");
			$("current-keywords8-value").set({text : "AND ("+$("ajax-keywords8").value+")" });		
			$("current-keywords8-dispose").addEvent('click', function() {
				$("current-keywords8-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords8").addClass("hidden");
				$("ajax-keywords8").set({value : ""});
				ajaxsubmit();
			});		
		}
		
		if ($("ajax-keywords9").value != "") {	
			addRemoveKeywordHeader();
			$("current-keywords9").removeClass("hidden");
			$("current-keywords9-value").set({text : "AND ("+$("ajax-keywords9").value+")" });			
			$("current-keywords9-dispose").addEvent('click', function() {
				$("current-keywords9-dispose").removeEvents('click');
				addRemoveKeywordHeader();
				$("current-keywords9").addClass("hidden");
				$("ajax-keywords9").set({value : ""});
				ajaxsubmit();
			});		
		}		
		/*End - Keywords*/
		if (research_location.value != "" && research_location.value != this.research_location_value) {
			$("ajax-research_location").set({value : research_location.value});		
		}
		if ($("ajax-research_location").value != "") {
			$("current-research_location-header").removeClass("hidden");
			$("current-research_location").removeClass("hidden");
			$("current-research_location-value").set({text : $("ajax-research_location").value});
			research_location.set({value : this.research_location_value});
			$("current-research_location-dispose").addEvent('click', function() {
				$("current-research_location-header").addClass("hidden");
				$("current-research_location").addClass("hidden");
				$("ajax-research_location").set({value : ""});				
				ajaxsubmit();
			});
			
		}

		if (investigator.value != "" && investigator.value != this.investigator_value) {
			$("ajax-investigator").set({value : investigator.value});
		}
		if ($("ajax-investigator").value != "") {
			$("current-investigator-header").removeClass("hidden");
			$("current-investigator").removeClass("hidden");
			$("current-investigator-value").set({text : $("ajax-investigator").value});
			investigator.set({value : this.investigator_value});
			$("current-investigator-dispose").addEvent('click', function() {
				$("current-investigator-header").addClass("hidden");
				$("current-investigator").addClass("hidden");
				$("ajax-investigator").set({value : ""});				
				ajaxsubmit();
			});		
		}

		//Textbox
		if (organisation_involved.value != "" && organisation_involved.value != this.organisation_involved_value) {
			$("ajax-organisation_involved").set({value : organisation_involved.value});
		}
		if ($("ajax-organisation_involved").value != "") {
			$("current-organisation_involved-header").removeClass("hidden");
			$("current-organisation_involved").removeClass("hidden");
			$("current-organisation_involved-value").set({text : $("ajax-organisation_involved").value});
			organisation_involved.set({value : this.organisation_involved_value});
			$("current-organisation_involved-dispose").addEvent('click', function() {
				$("current-organisation_involved-header").addClass("hidden");
				$("current-organisation_involved").addClass("hidden");
				$("ajax-organisation_involved").set({value : ""});
				ajaxsubmit();
			});		
		}

		if (type_of_project.value != "" && type_of_project.value != this.type_of_project_default_value) {
			$("current-type_of_project-header").removeClass("hidden");
			$("current-type_of_project").removeClass("hidden");
			$("current-type_of_project-value").set({text : type_of_project.value});
			$("ajax-type_of_project").set({value : type_of_project.value});
			type_of_project.set({value : this.type_of_project_default_value});
			$("current-type_of_project-dispose").addEvent('click', function() {
				$("current-type_of_project-header").addClass("hidden");
				$("current-type_of_project").addClass("hidden");
				$("ajax-type_of_project").set({value : ""});			
				ajaxsubmit();
			});
		} else {
			$("current-type_of_project-header").addClass("hidden");
			$("current-type_of_project").addClass("hidden");
			$("ajax-type_of_project").set({value : ""});
			//ajaxsubmit();
		}				
	}
	//remove keyword header
	function addRemoveKeywordHeader(){
		if($("ajax-keywords0").value=="" && $("ajax-keywords1").value=="" && $("ajax-keywords2").value==""
			&& $("ajax-keywords3").value=="" && $("ajax-keywords4").value==""
			&& $("ajax-keywords5").value=="" && $("ajax-keywords6").value==""
			&& $("ajax-keywords7").value=="" && $("ajax-keywords8").value==""
			&& $("ajax-keywords9").value==""){				
				$("current-keywords-header").addClass("hidden");				
		}
		else
			$("current-keywords-header").removeClass("hidden");
	}
//Refresh form
function ajaxsubmit(){		
	var result = $('result');
	data="&keywords0="+$("ajax-keywords0").value;
	data+="&keywords1="+$("ajax-keywords1").value;
	data+="&keywords2="+$("ajax-keywords2").value;
	data+="&keywords3="+$("ajax-keywords3").value;
	data+="&keywords4="+$("ajax-keywords4").value;
	data+="&keywords5="+$("ajax-keywords5").value;
	data+="&keywords6="+$("ajax-keywords6").value;
	data+="&keywords7="+$("ajax-keywords7").value;
	data+="&keywords8="+$("ajax-keywords8").value;
	data+="&keywords9="+$("ajax-keywords9").value;
	data+= "&research_location="+$("ajax-research_location").value;       
    data+="&investigator="+$("ajax-investigator").value;
    data+="&organisation_involved="+$("ajax-organisation_involved").value; 
    data+="&type_of_project="+$("ajax-type_of_project").value;
    data+="&limit="+$("ajax-limit").value;
    data+="&limitstart="+$("ajax-limitstart").value;
    data+="&filter_order="+$("ajax-filter_order").value;
    //alert(data);
	//Request
	var myRequest = new Request({
	    url: 'index.php?option=com_nrmresearch&view=currentresearchs&layout=ajax_result',
	    method: 'post',	   
	    onRequest: function() {	    		    		   
	    	var modal = new Element('div', {	    	   
	    	    class : 'result-loading'	    	    	    	   
	    	});
	    	result.grab(modal);	   	    	
	    },
	    onSuccess: function(responseText) {	    	
			result.set('html', responseText);	
			toggleItems($('ajax-limit').value);	
			addAjaxNavigator();
	    },
	    onFailure: function() {
	        alert("failed");
	    }
	}).send(data); 
}



